package assembler;

public class PiscinaRegistros {

	 private Registro[] registros;

	    
	    public PiscinaRegistros() {
		super();
		this.registros = new Registro[4];
		Registro eax = new Registro(true,true,"EAX","AX","AH","AL");
        Registro ebx = new Registro(true,true,"EBX","BX","BH","BL");
        Registro ecx = new Registro(true,true,"ECX","CX","CH","CL");
        Registro edx = new Registro(true,true,"EDX","DX","DH","DL");
        registros[0] = ecx;
        registros[1] = edx;
        registros[2] = ebx;
        registros[3] = eax;
	}

		public boolean getEAX(){
	        if (registros[3].isH() && registros[3].isL()){
	            registros[3].setH(false);
	            registros[3].setL(false);
	            return true;
	        }
	            return false;
	    }

	    public boolean getEBX(){
	        if (registros[2].isH() && registros[2].isL()){
	            registros[2].setH(false);
	            registros[2].setL(false);
	            return true;
	        }
	            return false;
	    }

	    public boolean getECX(){
	        if (registros[0].isH() && registros[0].isL()){
	            registros[0].setH(false);
	            registros[0].setL(false);
	            return true;
	        }
	            return false;
	    }

	    public boolean getEDX(){
	        if (registros[1].isH() && registros[1].isL()){
	            registros[1].setH(false);
	            registros[1].setL(false);
	            return true;
	        }
	        else
	            return false;
	    }

	    public String get32bits(){
	        for (int i = 0; i < registros.length; i++) {
	            String s = registros[i].get32bits();
	            if (s != null)
	                return s;
	        }
	        return null;
	    }

	    public String get16bits(){
	        for (int i = 0; i < registros.length; i++) {
	            String s = registros[i].get16bits();
	            if (s != null)
	                return s;
	        }
	        return null;
	    }

	    public String get8bits(){
	        for (int i = 0; i < registros.length; i++) {
	            String s = registros[i].get8bits();
	            if (s != null)
	                return s;
	        }
	        return null;
	    }

	    public void vaciarRegistro(String nombre){
	        for (int i = 0; i < registros.length; i++) {
	            if (registros[i].vaciar(nombre))
	                break;
	        }
	    }
}
